package org.jash.shop2202.goods

import android.view.MenuItem
import android.widget.Toast
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.google.android.material.snackbar.Snackbar
import com.hyphenate.helpdesk.easeui.util.IntentBuilder
import dagger.hilt.android.AndroidEntryPoint
import org.jash.shop2202.databinding.ActivityDetailBinding
import org.jash.shop2202.mvvm.BaseActivity

@Route(path = "/shop/detail")
@AndroidEntryPoint
class DetailActivity : BaseActivity<ActivityDetailBinding, DetailViewModel>() {
    @Autowired
    @JvmField
    var id:Int = 0
    override fun initData() {
        ARouter.getInstance().inject(this)
        viewModel.goodsLiveData.observe(this) {
            binding.goods = it
        }
        viewModel.addCartLiveData.observe(this) {
            Toast.makeText(this, it, Toast.LENGTH_SHORT).show()
        }
        viewModel.loadDetail(id)
    }

    override fun initView() {
        setSupportActionBar(binding.toolbar)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        binding.addCart.setOnClickListener {
            viewModel.addCart(id)
        }
        binding.action.setOnClickListener {
            Snackbar.make(binding.container, "提示", Snackbar.LENGTH_LONG).show()
        }
        binding.buy.setOnClickListener {
            ARouter.getInstance()
                .build("/shop/pay")
                .withString("content", binding.goods?.goods_desc)
                .withFloat("price", binding.goods?.goods_default_price ?: 0f)
                .navigation()
        }
        binding.agent.setOnClickListener {
            val intent =  IntentBuilder(this)
                .setServiceIMNumber("kefuchannelimid_373477") //获取地址：kefu.easemob.com，“管理员模式 > 渠道管理 > 手机APP”页面的关联的“IM服务号”
                .build();
            startActivity(intent);
        }
    }


}